/**
@C++ Standard: 11
@Copyright:Copyright (c) 2019 Harold Hu. All rights reserved.
@Author: Created by Harold Hu with CLion on 2019/1/12 14:22.
@File Name: BOOSTTEST_MAIN.cpp
@Description: For boostTest Framework.
*/
#include "HaroldDebug.h"

#if TEST_TYPE == TEST_BOOST
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE

#include <boost/test/unit_test.hpp>

int add(int i, int j)
{
	return i + j;
}


/* test_suite1 start */
BOOST_AUTO_TEST_SUITE(test_suite1)
	// test_case1 in test_suite1
	BOOST_AUTO_TEST_CASE(test_case1)
	{
		BOOST_WARN(add(2, 2) == 4);
	}
	// test_case2 in test_suite1
	BOOST_AUTO_TEST_CASE(test_case2)
	{
		BOOST_REQUIRE_EQUAL(add(2, 3), 5);  // note: REQUIRE
		if (add(2, 4) != 6)
		{
			BOOST_FAIL("Should never reach this line");
		}
	}

BOOST_AUTO_TEST_SUITE_END()
/* test_suite1 end */

/* test_suite2 start */
BOOST_AUTO_TEST_SUITE(test_suite2)
	// test_case3 in test_suite2
	BOOST_AUTO_TEST_CASE(test_case3)
	{
		BOOST_CHECK(true);
	}

BOOST_AUTO_TEST_SUITE_END()
/* test_suite2 end */

// test_case_on_file_scope
BOOST_AUTO_TEST_CASE(test_case_on_file_scope)
{
	BOOST_CHECK(true);
}

/* test_suite2 start */
BOOST_AUTO_TEST_SUITE(test_suite2)
	// test_case4 in test_suite2
	BOOST_AUTO_TEST_CASE(test_case4)
	{
		BOOST_CHECK(true);
	}

BOOST_AUTO_TEST_SUITE_END()
/* test_suite2 end */


/* 测试夹具 */
/* 3) Global localFixture */
struct globalFixture
{
	globalFixture() : g_i(0)
	{
		std::cout << "boost TestFramework setup\n";
	}
	
	~globalFixture()
	{
		std::cout << "g_i: " << g_i << std::endl;
		std::cout << "boost TestFramework teardown\n";
	}
	
	int g_i;
};

BOOST_GLOBAL_FIXTURE(globalFixture);

/* 1) Per TestFramework case localFixture */
struct localFixture
{
	localFixture() : i(0)
	{
		std::cout << "setup localFixture\n";
	}
	
	~localFixture()
	{
		std::cout << "teardown localFixture\n";
	}
	
	int i;
};

BOOST_FIXTURE_TEST_CASE(test_case01, localFixture)
{
	BOOST_CHECK(i == 0);  // failed: i == 0
	++i;
}

BOOST_FIXTURE_TEST_CASE(test_case02, localFixture)
{
	BOOST_CHECK_EQUAL(i, 0);  // pass: i == 0
}

BOOST_AUTO_TEST_CASE(test_case03)
{
	BOOST_CHECK(true);
}

/* 2) TestFramework suite level localFixture */
BOOST_FIXTURE_TEST_SUITE(test_suite01, localFixture)
	
	BOOST_AUTO_TEST_CASE(test_case01)
	{
		BOOST_CHECK(i == 0);  // failed: i == 0
		++i;
	}
	
	BOOST_AUTO_TEST_CASE(test_case02)
	{
		BOOST_CHECK_EQUAL(i, 0);  // pass: i == 0
	}

BOOST_AUTO_TEST_SUITE_END()


#endif